<?php

namespace App\Admin\Controllers;

use App\Admin\Metrics\Home\Statistics;
use App\Admin\Repositories\DayTime;
use App\Enums\CurrencyAssetEnum;
use App\Http\Controllers\Controller;
use App\Models\CurrencyAsset;
use App\Models\JobPositionUpdateModel;
use App\Models\User;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Card;
use Illuminate\Support\Facades\DB;

class HomeController extends Controller
{
    public function index(Content $content)
    {

        $day = now()->format('Y-m-d');
        $new_active_user = User::whereDate('user.created_at', $day)
            ->join('sign_up_job_position', 'user.id', '=', 'sign_up_job_position.user_id')
            ->whereDate('sign_up_job_position.created_at', $day)
            ->distinct('user.id')
            ->count('user.id');;
        $top = [
            [
                'name' => '用户总数',
                'value' => User::query()->count(),
            ],
            [
                'name' => '今日新增',
                'value' => User::query()->where('created_at', '>', now()->today()->toDateTimeString())->count(),
            ],
            [
                'name' => '今日活跃',
                'value' => $new_active_user,
            ],
        ];

        $body = function (Row $row) use ($top) {
            $row->column(12, admin_view('admin.home', compact('top')));
            $row->column(12, new Statistics());
        };

        return $content
            ->header('系统首页')
            ->description('欢迎您登录')
            ->body($body);
    }
    public function statistics() {}
}
